<template>
    <div class="wxSignIn">

    </div>
</template>
<script>
export default {
  name: "wxSignIn",
  data() {
    return {
      token: localStorage.getItem("token")?localStorage.getItem("token"):'',
      tokenParams:{
          token:localStorage.getItem("token")?localStorage.getItem("token"):''
      },
    };
  },
  created() {
    this.wxSignIn();
  },
  methods: {
    //   本地
      wxSignIn() {
          console.log(window.location.href)
          return;
      let REDIRECT_URI = encodeURI("https://xcx.bluecoord.com");
      if (!this.$route.query.code) {
        /*没跳转之前 */
        let REDIRECT_URI = this.thisUrl;
        window.location.href =
          "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
          this.APPID +
          "&redirect_uri=" +
          encodeURI("http://192.168.0.101:8080") +
          "&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
      } else {
        /*跳转之后获取到了code*/
        let wxCodeParams = {
          code: "061cTlm60ANmfJ1NtHm60pklm60cTlmy" //this.$route.query.code
        };
        this.axios.post(this.APIHOST + "home/login2", wxCodeParams).then(r => {
          if (r.data.code === "0") {
            localStorage.setItem("token", r.data.data.token);
            this.$store.commit("setToken", "?token=" + r.data.data.token);
            this.$store.commit("setMyUserInfo", r.data.data);
            this.$router.push(localStorage.getItem("fromUrl"));
          }
          if (r.data.code === "1010") {
            this.$p_message(r.data.msg);
          }
        });
      }
    },



//线上
    // wxSignIn() {
    //   let REDIRECT_URI0 = encodeURI(window.location.href.split('#')[0]);
    //   let REDIRECT_URI1 = encodeURI(window.location.href.split('#')[1]);
    //   if (!this.$route.query.code) {
    //     /*没跳转之前 */
    //     // let REDIRECT_URI = this.thisUrl;
    //     window.location.href =
    //       "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
    //       this.APPID +"&redirect_uri="+REDIRECT_URI0+'#'+REDIRECT_URI1+"&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
    //   } else {
    //     /*跳转之后获取到了code*/
    //     let wxCodeParams = {
    //       code: this.$route.query.code //this.$route.query.code
    //     };
    //     this.axios.post(this.APIHOST + "home/login2", wxCodeParams).then(r => {
    //       if (r.data.code === "0") {
    //         localStorage.setItem("token", r.data.data.token);
    //         this.$store.commit("setToken", "?token=" + r.data.data.token);
    //         this.$store.commit("setMyUserInfo", r.data.data);
    //         this.$router.push(localStorage.getItem("fromUrl"));
    //       }
    //       if (r.data.code === "1010") {
    //         this.$p_message(r.data.msg);
    //       }
    //     });
    //   }
    // }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      localStorage.setItem("fromUrl", from.path);
    });
  },
  beforeRouteLeave(to, from, next) {
    localStorage.removeItem("fromUrl");
    next();
  }
};
</script>

